import os
import shutil

def clear_pycache(root_dir):
    for dirpath, dirnames, filenames in os.walk(root_dir):
        if '__pycache__' in dirnames:
            pycache = os.path.join(dirpath, '__pycache__')
            print(f"Deleting {pycache}")
            try:
                shutil.rmtree(pycache)  # 全平台通用
            except Exception as e:
                print(f"Error deleting {pycache}: {e}")

if __name__ == "__main__":
    clear_pycache(".")
